ABC264 C - Matrix Reducing
https://atcoder.jp/contests/abc264/tasks/abc264_c
提出
code: python
h1, w1 = list(map(int, input().split()))
a = list(map(int, input().split())) for _ in range(h1)
h2, w2 = list(map(int, input().split()))
b = list(map(int, input().split())) for _ in range(h2)
aa = [False for _ in range(w1) for _ in range(h1)]
#2の20乗
for bt in b:
t = bt.pop(0)
解答
code: python
import itertools
h1, w1 = list(map(int, input().split()))
a = list(map(int, input().split())) for _ in range(h1)
h2, w2 = list(map(int, input().split()))
b = list(map(int, input().split())) for _ in range(h2)
def check(tmpa):
for i in range(h2):
for j in range(w2):
if not tmpaij == bij:
return False
return True
# 使用する行・列を全探索
for hc in itertools.combinations(range(h1), h2):
for wc in itertools.combinations(range(w1), w2):
# 全探索した結果から新しい行列 a' を作る
tmpa = []
for h in hc:
row = []
for w in wc:
row.append(ahw)
tmpa.append(row)
# b と一致するか
if check(tmpa):
print("Yes")
exit()
print("No")
メモ
PythonでAtCoder Beginner Contest 264 の解説とか感想とか(A~E問題)
提出
AC/WA
code: python
from collections import defaultdict
h1, w1 = map(int, input().split())
a = list(map(int, input().split())) for _ in range(h1)
h2, w2 = map(int, input().split())
b = list(map(int, input().split())) for _ in range(h2)
# print(a) 1, 2, 3, 4, 5], 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, [16, 17, 18, 19, 20
# print(b) 6, 8, 9], [16, 18, 19
av = []
for h2i in range(h2):
for w2i in range(w2):
flag = False
bi = bh2iw2i
for h1i in range(h1):
for w1i in range(w1):
ai = ah1iw1i
if ai == bi:
flag = True
av.append((h1i, w1i))
if not flag:
print("No")
exit()
# print(av)
# (1, 0), (1, 2), (1, 3), (3, 0), (3, 2), (3, 3)
d = defaultdict(list)
for h1i, w1i in av:
dh1i.append(w1i)
dv = []
for di in d.values():
dv.append(di)
for i in range(len(dv) - 1):
if dvi != dvi+1:
print("No")
exit()
print("Yes")